/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.istia.gesstages.jpa;

import java.io.Serializable;
import javax.persistence.*;

@Entity
@Table(name = "users")
public class User implements Serializable {

    public User() {
    }

    public User(UserType type, String login, String mdp, String nom, String prenom, String mail, Boolean subscribed, String promo) {
        this.type = type;
        this.login = login;
        this.mdp = mdp;
        this.nom = nom;
        this.prenom = prenom;
        this.mail = mail;
        this.subscribed = subscribed;
        this.promo = promo;
    }
    @Id
    @Column(name = "user_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    @Column(name = "user_version", nullable = false)
    private int version;
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "user_type", nullable = false)
    private UserType type;
    @Column(name = "user_login", nullable = false, length = 50)
    private String login;
    @Column(name = "user_mdp", nullable = false, length = 32)
    private String mdp;
    @Column(name = "user_nom", nullable = false)
    private String nom;
    @Column(name = "user_prenom", nullable = false)
    private String prenom;
    @Column(name = "user_mail", nullable = false)
    private String mail;
    @Column(name = "user_mailinglist", nullable = false)
    private Boolean subscribed;
    @Column(name = "user_promo", nullable = false, length = 4)
    private String promo;
    @OneToOne
    @JoinColumn(name = "user_attribution", nullable = true, unique = true)
    private Offer attribution;

    @Override
    public boolean equals(Object obj) {
        if (obj.getClass() == User.class) {
            User u = (User) obj;
            return u.getId() == this.getId();
        } else {
            return super.equals(obj);
        }
    }

    public Offer getAttribution() {
        return attribution;
    }

    public void setAttribution(Offer attribution) {
        this.attribution = attribution;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getMdp() {
        return mdp;
    }

    public void setMdp(String mdp) {
        this.mdp = mdp;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getPrenom() {
        return prenom;
    }

    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }

    public String getPromo() {
        return promo;
    }

    public void setPromo(String promo) {
        this.promo = promo;
    }

    public Boolean getSubscribed() {
        return subscribed;
    }

    public void setSubscribed(Boolean subscribed) {
        this.subscribed = subscribed;
    }

    public UserType getType() {
        return type;
    }

    public void setType(UserType type) {
        this.type = type;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }
}
